{include file='admin/header.html'}

<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.username}</label>
        <div class="layui-input-inline">
            <input type="text" name="username" value="{$user.username}" disabled="disabled" placeholder="{$tran.input_username}" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">{$tran.not_modify}</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.password}</label>
        <div class="layui-input-inline">
            <input type="password" name="password" value="" placeholder="{$tran.empty_no_modify}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.email}</label>
        <div class="layui-input-inline">
            <input type="email" name="email" value="{$user.email}" placeholder="{$tran.fetch_password} ({$tran.optional})" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline captcha" style="width:75px;">
            <input type="text" name="captcha" value="" autocomplete="off" placeholder="{$tran.verycode}" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:auto;">
            <button type="button" class="layui-btn layui-btn-primary" lay-on="verycode">{$tran.fetch_verycode}</button>
        </div>
        <div class="layui-form-mid layui-word-aux">{$tran.change_email_use}</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.nickname}</label>
        <div class="layui-input-inline">
            <input type="text" name="nickname" value="{$user.nickname}" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.phone}</label>
        <div class="layui-input-inline">
            <input type="text" name="phone" value="{$user.phone}" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.avatar}</label>
        <div class="layui-input-inline">
            <input type="text" name="avatar" value="{$user.avatar}" autocomplete="off" class="layui-input upload">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.role}</label>
        <div class="layui-input-inline">
            <select name="role_id">
                <option value="">{$tran.choose}</option>
                {foreach from="$role" item="_role"}
                <option value="{$_role.id}"{if $user.role_id == $_role.id} selected{/if}>{$_role.name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.language_permission}</label>
        {if $langs}
        <div class="layui-input-inline">
            {foreach from="$langs" item="_lang"}
            <input type="checkbox" name="lang_slugs[]" value="{$_lang.slug}" {if in_array($_lang.slug, $lang_slugs)} checked{/if} title="{$_lang.name} （{$_lang.title}）" lay-skin="primary">
            {/foreach}
        </div>
        {/if}
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">{$tran.status}</label>
        <div class="layui-input-block">
            <input type="hidden" name="status" value="1">
            <input type="checkbox" name="status" value="0" lay-skin="switch"{if $user.status == 0} checked{/if}{if $user.id==1} disabled{/if} lay-text="ON|OFF">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{$user.id}">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="submit">{$tran.save}</button>
            <button type="reset" class="layui-btn layui-btn-primary">{$tran.reset}</button>
        </div>
    </div>
</form>

<script>
    // JS
    layui.use(['layer', 'util'], function () {
        var layer = layui.layer,
            util = layui.util,
            $ = layui.jquery;

        // 获取验证码
        util.event('lay-on', {
            verycode: function (othis) {
                var email = othis.parent().parent().find('input[name="email"]').val();
                // 倒计时函数
                var count = 60;
                othis.attr('disabled', true).addClass('layui-btn-disabled');
                var timer = setInterval(function () {
                    count--;
                    othis.text('{$tran.resend} (' + count + ')');
                    if (count <= 0) {
                        clearInterval(timer);
                        othis.attr('disabled', false).removeClass('layui-btn-disabled').text('{$tran.fetch_verycode}');
                    }
                }, 1000);
                $.post('{$site_url}/{$lang}/admin/user/edit/{$user.id}.html', { email: email }, function (res) {
                    if (res.code) {
                        clearInterval(timer);
                        othis.attr('disabled', false).removeClass('layui-btn-disabled').text('{$tran.fetch_verycode}');
                        return layer.alert(res.msg, { title: '{$tran.info}', icon: 2, btn: ['{$tran.ok}'] });
                    }
                    layer.msg(res.msg, { icon: 1, time: 3000 });
                }, 'json');
            }
        });
    });
</script>


{include file='admin/inc/form.html'}

{include file='admin/footer.html'}